﻿using System.Windows.Controls;
using Dsl.Ped.Framework.Common;
using Dsl.Ped.Framework.WPFControls.ProjectiveObject;

namespace Dsl.Ped.Framework.Helpers
{
    /// <summary>
    /// Helper methods for the <see cref="ContentPresenter"/>
    /// </summary>
    public class ContentPresenterHelper
    {
        /// <summary>
        /// Set the <see cref="ContentPresenter"/> based on the type of <see cref="obj"/>.
        /// For the IProjective a Projective Object User Control is set as a content, otherwise
        /// a common content presenter is set as a content
        /// </summary>
        /// <param name="contentPresenter"><see cref="ContentPresenter"/> we want to configure</param>
        /// <param name="obj">Object by which we want to configure the presenter</param>
        public static void SetContentBasedOnType(ContentPresenter contentPresenter, object obj)
        {
            if (obj != null)
            {
                if (obj is IProjective)
                {
                    var projectiveObjectUserControl = new ProjectiveObjectUserControl();
                    projectiveObjectUserControl.ProjectiveObject = obj as IProjective;
                    projectiveObjectUserControl.IsTabStop = false;

                    contentPresenter.Content = projectiveObjectUserControl;
                }
                else if (obj is IProjection)
                {
                    contentPresenter.Content = (obj as IProjection).View;
                }
                else
                {
                    contentPresenter.Content = obj.ToString();
                }
            }
        }
    }
}
